package com.ld.poetry.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ld.poetry.config.LoginCheck;
import com.ld.poetry.config.PoetryResult;
import com.ld.poetry.entity.PhotoWall;
import com.ld.poetry.service.PhotoWallService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * 照片墙(PhotoWall)表控制层
 *
 * @author makejava
 * @since 2023-08-19 22:45:06
 */
@RestController
@RequestMapping("photoWall")
public class PhotoWallController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private PhotoWallService photoWallService;

    /**
     * 分页查询所有数据
     *
     * @param page      分页对象
     * @param photoWall 查询实体
     * @return 所有数据
     */
    @GetMapping("/selectAll")
    public PoetryResult selectAll(Page<PhotoWall> page, PhotoWall photoWall) {
        return PoetryResult.success(this.photoWallService.page(page, new QueryWrapper<>(photoWall)));
    }
    /**
     * 查询所有数据
     *
     * @param photoWall 查询实体
     * @return 所有数据
     */
    @GetMapping("/list")
    public PoetryResult list(PhotoWall photoWall) {
        return PoetryResult.success(this.photoWallService.list(new QueryWrapper<>(photoWall)));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    @LoginCheck
    public PoetryResult selectOne(@PathVariable Serializable id) {
        return PoetryResult.success(this.photoWallService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param photoWall 实体对象
     * @return 新增结果
     */
    @PostMapping("/add")
    @LoginCheck
    public PoetryResult insert(@RequestBody PhotoWall photoWall) {
        return PoetryResult.success(this.photoWallService.save(photoWall));
    }

    /**
     * 修改数据
     *
     * @param photoWall 实体对象
     * @return 修改结果
     */
    @PostMapping("/update")
    @LoginCheck
    public PoetryResult update(@RequestBody PhotoWall photoWall) {
        return PoetryResult.success(this.photoWallService.updateById(photoWall));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @GetMapping("/delete")
    @LoginCheck
    public PoetryResult delete(@RequestParam("id") List<Long> idList) {
        return PoetryResult.success(this.photoWallService.removeByIds(idList));
    }
}

